// import { SEARCH_FOCUS, SEARCH_BLUR } from './actionTypes';
import * as actionTypes from './actionTypes';
import { fromJS } from 'immutable';
import axios from 'axios';

const initSearchList = (data) => ({
	type: actionTypes.INIT_SEARCH_LIST,
	data: fromJS(data),
	totalPage: Math.ceil(data.length / 5)
});

export const searchFocus = () => ({
	type: actionTypes.SEARCH_FOCUS
});

export const searchBlur = () => ({
	type: actionTypes.SEARCH_BLUR
});

export const mouseEnter = () => ({
	type: actionTypes.MOUSE_ENTER
})

export const mouseLeave = () => ({
	type: actionTypes.MOUSE_LEAVE
})

export const changePageList = (page) => ({
	type: actionTypes.CHANGE_PAGE,
	page
})

export const getList = () => {
	return (dispatch) => {
		axios.get('/mock/headerList.json').then(res => {
			const data = res.data.list;
			dispatch(initSearchList(data));
		}).catch(err => {
			console.log('请求失败');
		});
	}
}